/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistencia;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 *
 * @author eli
 */
public class FabricaConexao
{
    Connection con;
    
    public Connection fazConexao()
    {
        try
        {
            //Class.forName("org.gjt.mm.mysql.Driver");
            String url = "jdbc:mysql://localhost:3306/bancoswing1";
            con = DriverManager.getConnection(url, "root", "server");
            con.setAutoCommit(false);
        }
        catch( Exception e )
        {
            //e.printStackTrace();
            //throw new java.lang.RuntimeException("erro ao conectar");
        }
        
        return con;
    }
    
    public void commitConexao()
    {
        try
        {
            con.commit();
        }
        catch( Exception e ){}
    }
    
    public void rollbackConexao()
    {
        try
        {
            con.rollback();
        }
        catch( Exception e ){}
    }
    
    public void fecharConexao()
    {
        // Fechando a conexão
        try
        {
            con.close();
        }
        catch( Exception e )
        {
            //e.printStackTrace();
            //throw new java.lang.RuntimeException("erro fechar");
        }
    }
}
